home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / Development / PartMaker / Container•1.0d11v2 / Container•1.0d11v2.rsrc / dFRK_5128 < prev    next >
Encoding:
Text File  |  1995-12-08  |  11.7 KB  |  442 lines

  1. //========================================================================================
  2. //
  3. //    File:                ContainerView.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Author:                Laurent Delamare
  7. //
  8. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Container.hpp"
  13.  
  14. #ifndef CONTAINERVIEW_H
  15. #include "ContainerView.h"
  16. #endif
  17.  
  18. #ifndef CONTAINERDEF_H
  19. #include "ContainerDef.h"
  20. #endif
  21.  
  22. #ifndef CONTAINERPART_H
  23. #include "ContainerPart.h"
  24. #endif
  25.  
  26. #ifndef CONTAINERFRM_H
  27. #include "ContainerFrm.h"
  28. #endif
  29.  
  30. #ifndef EDITCMDS_H
  31. #include "EditCmds.h"
  32. #endif
  33.  
  34. #ifndef CONTAINERSEL_H
  35. #include "ContainerSel.h"
  36. #endif
  37.  
  38. #ifndef BASESHP_H
  39. #include "BaseShp.h"
  40. #endif
  41.  
  42. #ifndef BOUNDSHP_H
  43. #include "BoundShp.h"
  44. #endif
  45.  
  46. #ifndef LINESHP_H
  47. #include "LineShp.h"
  48. #endif
  49.  
  50. #ifndef OVALSHP_H
  51. #include "OvalShp.h"
  52. #endif
  53.  
  54. #ifndef RECTSHP_H
  55. #include "RectShp.h"
  56. #endif
  57.  
  58. #ifndef RRECTSHP_H
  59. #include "RRectShp.h"
  60. #endif
  61.  
  62. #ifndef TEXTSHP_H
  63. #include "TextShp.h"
  64. #endif
  65.  
  66. #ifndef CONTAINERPRXY_H
  67. #include "ContainerPrxy.h"
  68. #endif
  69.  
  70. #ifndef SHPTRAKR_H
  71. #include "ShpTrakr.h"
  72. #endif
  73.  
  74. #ifndef CONTAINERCMDS_H
  75. #include "ContainerCmds.h"
  76. #endif
  77.  
  78. #ifndef CONTAINERCLIP_H
  79. #include "ContainerClip.h"
  80. #endif
  81.  
  82. #ifndef UTILS_H
  83. #include "Utils.h"
  84. #endif
  85.  
  86. #ifndef CONTAINERDDCMD_H
  87. #include "ContainerDDCmd.h"
  88. #endif
  89.  
  90. // ----- Framework Layer -----
  91.  
  92. #ifndef FWUTIL_H
  93. #include "FWUtil.h"
  94. #endif
  95.  
  96. #ifndef FWPRESEN_H
  97. #include "FWPresen.h"
  98. #endif
  99.  
  100. #ifndef FWSCROLR_H
  101. #include "FWScrolr.h"
  102. #endif
  103.  
  104. #ifndef FWSCLBAR_H
  105. #include "FWSclBar.h"
  106. #endif
  107.  
  108. #ifndef FWGROWBX_H
  109. #include "FWGrowBx.h"
  110. #endif
  111.  
  112. // ----- OS Layer -----
  113.  
  114. #ifndef FWMENU_H
  115. #include "FWMenu.h"
  116. #endif
  117.  
  118. #ifndef FWRECSHP_H
  119. #include "FWRecShp.h"
  120. #endif
  121.  
  122. #ifndef FWCURSOR_H
  123. #include "FWCursor.h"
  124. #endif
  125.  
  126. #ifndef FWEVENT_H
  127. #include "FWEvent.h"
  128. #endif
  129.  
  130. #ifndef FWODGEOM_H
  131. #include "FWODGeom.h"
  132. #endif
  133.  
  134. #ifndef FWLINSHP_H
  135. #include "FWLinShp.h"
  136. #endif
  137.  
  138. #ifndef FWBMPSHP_H
  139. #include "FWBmpShp.h"
  140. #endif
  141.  
  142. // ----- OpenDoc Includes -----
  143.  
  144. #ifndef SOM_Module_OpenDoc_Commands_defined
  145. #include <CmdDefs.xh>
  146. #endif
  147.  
  148. #ifndef SOM_Module_OpenDoc_StdProps_defined
  149. #include <StdProps.xh>
  150. #endif
  151.  
  152. #ifndef SOM_ODSession_xh
  153. #include <ODSessn.xh>
  154. #endif
  155.  
  156. #ifndef SOM_ODDispatcher_xh
  157. #include <Disptch.xh>
  158. #endif
  159.  
  160. //========================================================================================
  161. // RunTime Info
  162. //========================================================================================
  163.  
  164. #ifdef FW_BUILD_MAC
  165. #pragma segment containerframes
  166. #endif
  167.  
  168. FW_DEFINE_CLASS_M1(CContainerView, FW_CView);
  169.  
  170. //========================================================================================
  171. // CContainerView
  172. //========================================================================================
  173.  
  174. //----------------------------------------------------------------------------------------
  175. // CContainerView::CContainerView
  176. //----------------------------------------------------------------------------------------
  177.  
  178. CContainerView::CContainerView(Environment* ev, CContainerFrame* frame, FW_CRect& bounds, CContainerPart* containerPart) :
  179.     FW_CView(ev, (FW_CView*)frame, bounds),
  180.     fContainerPart(containerPart),
  181.     fContainerFrame(frame)
  182. {    
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. // CContainerView::~CContainerView
  187. //----------------------------------------------------------------------------------------
  188.  
  189. CContainerView::~CContainerView()
  190. {
  191. }
  192.  
  193. //----------------------------------------------------------------------------------------
  194. // CContainerView::Draw
  195. //----------------------------------------------------------------------------------------
  196.  
  197. void CContainerView::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  198. {
  199.     // Render inside the content view
  200.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  201.     FW_CRect invalidRect;
  202.     vc.GetClipRect(invalidRect);
  203.  
  204.     FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  205.  
  206.     // ----- Determine what to Render -----
  207.     ODCanvas* canvas = odFacet->GetCanvas(ev);
  208.     FW_Boolean dynamicCanvas = canvas->IsDynamic(ev);
  209.  
  210.     // ----- Render the grid -----
  211.     if (dynamicCanvas)
  212.         DrawGrid(ev, vc, invalidRect);
  213.  
  214.     // ----- Render every shape -----
  215.     FW_CRect updateBox;
  216.     FW_COrderedCollectionIterator ite(fContainerPart->GetShapeList());
  217.     for (CBaseShape* theShape = (CBaseShape*)ite.First(); ite.IsNotComplete(); theShape = (CBaseShape*)ite.Next())
  218.     {
  219.         theShape->GetUpdateBox(updateBox);
  220.         if (invalidRect.IsIntersecting(updateBox))
  221.             theShape->RenderShape(ev, odFacet, vc);
  222.     }
  223.  
  224.     // ----- Render selections Handles -----
  225.     if (IsActive(ev) && dynamicCanvas)    {    // Do not render handles for print / print preview
  226.         fContainerFrame->GetSelection(ev)->RenderSelectionHandles(ev, vc);
  227.     }
  228. }
  229.  
  230. //----------------------------------------------------------------------------------------
  231. // CContainerView::AdjustCursor
  232. //----------------------------------------------------------------------------------------
  233.  
  234. FW_Boolean CContainerView::AdjustCursor(Environment *ev, ODFacet* facet, const FW_CPoint& where)
  235. {
  236.     FW_Boolean cursorAdjusted = FW_CView::AdjustCursor(ev, facet, where);
  237.     
  238.     if (!cursorAdjusted && 
  239.         fContainerPart->GetActiveFrame(ev) == (FW_CFrame*)fContainerFrame && 
  240.             fContainerPart->GetTool() != kSelectTool)
  241.     {
  242.         FW_gCrossHairCursor.Select();
  243.         cursorAdjusted = TRUE;
  244.     }
  245.  
  246.     return cursorAdjusted;
  247. }
  248.  
  249. //----------------------------------------------------------------------------------------
  250. // CContainerView::DoMouseDown
  251. //----------------------------------------------------------------------------------------
  252.  
  253. FW_Boolean CContainerView::DoMouseDown(Environment *ev, const FW_CMouseEvent& theMouseEvent)
  254. {
  255.     ODFacet*         theFacet = theMouseEvent.GetFacet(ev);
  256.     CContainerSelection*    selection = fContainerFrame->GetSelection(ev);
  257.     
  258.     if (fContainerPart->GetTool() == kSelectTool)
  259.     {
  260.         if (selection->IsMouseInDraggableItem(ev, fContainerFrame, theMouseEvent, FALSE))
  261.         {
  262.             fContainerFrame->Drag(ev, theMouseEvent);
  263.         }
  264.         else if (!selection->Resize(ev, theMouseEvent))
  265.         {
  266.             selection->SelectWithRectangle(ev, theMouseEvent);
  267.         }
  268.                             
  269.         return TRUE;
  270.     }
  271.     
  272.     // ----- If read only don't want to create a new shape -----
  273.     if (fContainerPart->IsReadOnly(ev))
  274.     {
  275.         FW_Beep();
  276.         return TRUE;
  277.     }
  278.     
  279.     // ----- Create a new shape -----
  280.     CBaseShape *theShape =  fContainerPart->NewShape(ev, fContainerPart->GetTool() - kLine + kLineShape);
  281.     
  282.     FW_TRY
  283.     {
  284.         FW_PStyle trackStyle(fContainerPart->GetRenderVerb() == kFillOnly ? FW_kFixedPos1 : fContainerPart->GetPenSize(), FW_kGrayPat);
  285.         FW_PInk trackInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
  286.         theShape->ChangeRenderVerb(ev, fContainerPart, kFrameOnly);
  287.         theShape->SetFrameInk(trackInk);
  288.         theShape->SetFrameStyle(trackStyle);
  289.         
  290.         CShapeTracker tracker(ev, this, theFacet, theShape, fContainerPart->IsAutoGridOn());
  291.         if (tracker.Track(ev, theMouseEvent))
  292.         {
  293.             theShape->SetFrameInk(FW_kNormalInk);
  294.             theShape->SetFrameStyle(FW_kNormalStyle);
  295.             
  296.             FW_CColor color;
  297.     
  298.             theShape->ChangeRenderVerb(ev, fContainerPart, fContainerPart->GetRenderVerb());
  299.             theShape->ChangePenSize(ev, fContainerPart, fContainerPart->GetPenSize());
  300.                     
  301.             fContainerPart->GetFrameColor(color);
  302.             theShape->ChangeFrameColor(ev, fContainerPart, color);
  303.     
  304.             fContainerPart->GetFillColor(color);
  305.             theShape->ChangeFillColor(ev, fContainerPart, color);
  306.     
  307.             theShape->ChangeFramePattern(ev, fContainerPart, fContainerPart->GetFramePattern());
  308.             theShape->ChangeFillPattern(ev, fContainerPart, fContainerPart->GetFillPattern());
  309.             
  310.             CContainerShapeCommand* cmd = FW_NEW(CContainerShapeCommand,
  311.                                             (ev, fContainerPart, fContainerFrame, selection, theShape));
  312.             fContainerPart->ExecuteCommand(ev, cmd);
  313.             
  314.             FW_CRect dragRect;
  315.             theShape->GetDragRect(dragRect);
  316.  
  317.             FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, dragRect);
  318.             
  319.             CContainerFacetClipper facetClipper(ev, fContainerPart);
  320.             facetClipper.Clip(ev, fContainerFrame->GetPresentation(ev), aqShape);
  321.             
  322.             FW_CViewContext vc(ev, this, theMouseEvent.GetFacet(ev));
  323.             theShape->RenderShape(ev, theFacet, vc);
  324.             
  325.             theShape->GetUpdateBox(ev, aqShape);
  326.             fContainerFrame->GetPresentation(ev)->Invalidate(ev, aqShape, theFacet);        // will not invalide theFacet
  327.         }
  328.         else
  329.         {
  330.             delete theShape;
  331.         }
  332.     }
  333.     FW_CATCH_BEGIN
  334.     FW_CATCH_EVERYTHING()
  335.     {
  336.         delete theShape;
  337.         FW_THROW_SAME();
  338.     }
  339.     FW_CATCH_END
  340.     
  341.     return TRUE;
  342. }
  343.  
  344. //----------------------------------------------------------------------------------------
  345. // CContainerView::DoMouseDownInEmbeddedFrameBorder
  346. //----------------------------------------------------------------------------------------
  347.  
  348. FW_Boolean CContainerView::DoMouseDownInEmbeddedFrameBorder(Environment *ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
  349. {    
  350.     fContainerPart->SetTool(ev, kSelectTool);
  351.  
  352.     GetFrame(ev)->Drag(ev, theBorderMouseEvent);
  353.     
  354.     return TRUE;
  355. }
  356.  
  357. //----------------------------------------------------------------------------------------
  358. // CContainerView::DoMouseDownInEmbeddedFrame
  359. //----------------------------------------------------------------------------------------
  360.  
  361. FW_Boolean CContainerView::DoMouseDownInEmbeddedFrame(Environment* ev, 
  362.                                                 const FW_CEmbeddedMouseEvent& theEmbeddedMouseEvent)
  363. {
  364.     FW_Boolean handled = TRUE;
  365.     
  366.     if (theEmbeddedMouseEvent.GetNumberOfClicks(ev) > 1)
  367.         GetFrame(ev)->OpenSelection(ev);
  368.     else
  369.         handled = DoMouseDown(ev, theEmbeddedMouseEvent);
  370.     
  371.     return handled;
  372. }
  373.  
  374. //----------------------------------------------------------------------------------------
  375. // CContainerView::DrawGrid
  376. //----------------------------------------------------------------------------------------
  377.  
  378. void CContainerView::DrawGrid(Environment *ev, FW_CGraphicContext& gc, const FW_CRect& invalidRect)
  379. {
  380.     if (fContainerFrame->IsGraphicsGridOn())
  381.     {
  382.         FW_BitPattern vertical = {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  383.         FW_BitPattern horizontal = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80};
  384.         
  385.         FW_PPattern verticalPat(vertical);
  386.         FW_PPattern horizontalPat(horizontal);
  387.         
  388.         FW_CFixed minY = FW_IntToFixed(72 * (invalidRect.top.AsInt() / 72));
  389.         FW_CFixed maxY = FW_IntToFixed(72 * ((invalidRect.bottom + FW_kFixed72).AsInt() / 72));
  390.         FW_CFixed minX = FW_IntToFixed(72 * (invalidRect.left.AsInt() / 72));
  391.         FW_CFixed maxX = FW_IntToFixed(72 * ((invalidRect.right + FW_kFixed72).AsInt() / 72));
  392.         
  393.         // skip top-most and left-most lines
  394.         FW_CFixed startX = (minX == FW_kFixed0) ? FW_kFixed72 : minX;
  395.         FW_CFixed startY = (minY == FW_kFixed0) ? FW_kFixed72 : minY;
  396.         
  397.         FW_PStyle lineStyle(FW_IntToFixed(0), verticalPat);
  398.         FW_CLineShape line(startX, minY, startX, maxY, FW_kNormalInk, lineStyle);
  399.  
  400.         for (FW_CFixed x = startX; x <= maxX; x += FW_kFixed72)
  401.         {
  402.             line.Render(gc);
  403.             line.MoveShape(FW_kFixed72, FW_IntToFixed(0));
  404.         }
  405.         
  406.         line.GetStyle()->SetPattern(horizontalPat);
  407.         line.SetLineStart(minX, startY);
  408.         line.SetLineEnd(maxX, startY);
  409.         
  410.         for (FW_CFixed y = startY; y <= maxY; y += FW_kFixed72)
  411.         {
  412.             line.Render(gc);
  413.             line.MoveShape(FW_IntToFixed(0), FW_kFixed72);
  414.         }
  415.     }
  416. }
  417.  
  418. //----------------------------------------------------------------------------------------
  419. //    CContainerView::Activate
  420. //----------------------------------------------------------------------------------------
  421.  
  422. FW_Boolean CContainerView::Activate(Environment* ev)
  423. {
  424.     FW_Boolean newState = FW_CView::Activate(ev);
  425.     
  426.     if (newState) {
  427.         fContainerFrame->GetSelection(ev)->RenderAllHandles(ev, fContainerFrame);
  428.     }
  429.         
  430.     return newState;
  431. }
  432.  
  433. //----------------------------------------------------------------------------------------
  434. //    CContainerView::Deactivate
  435. //----------------------------------------------------------------------------------------
  436.  
  437. void CContainerView::Deactivate(Environment* ev)
  438. {
  439.     FW_CView::Deactivate(ev);
  440.     fContainerFrame->GetSelection(ev)->RenderAllHandles(ev, fContainerFrame);
  441. }
  442.